﻿@{
    ViewBag.Title = "ManagerMenu";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}

@model Menu
@{
    List<Menu> lstMenu = ViewBag.lstMenu != null ? (List<Menu>)ViewBag.lstMenu : new List<Menu>();   
}

<div class="divlist">

    <div class="gird-title">
        <div class="gird-itemTitle row_01">ID</div>
        <div class="gird-itemTitle row_02">Name</div>
        <div class="gird-itemTitle row_03">Links</div>
        <div class="gird-itemTitle row_04 rowEnd">Order</div>
    </div>

    @{
        List<Menu> lstMenuParent = lstMenu.Where(d => d.ParentID == 0).OrderBy(d => d.MenuOrder).ToList();
        foreach (Menu itemParent in lstMenuParent)
        {
            <div class="gird-row">
                <div class="gird-item row_01">
                    <div class="checkbox" onclick="SetChecked($(this));" id="@itemParent.MenuID" >
                            @Html.Hidden("oder", itemParent.MenuID)                            
                        </div>
                </div>
                <div class="gird-item row_02">@itemParent.MenuName</div>
                <div class="gird-item row_03">@itemParent.MenuUrl</div>
                <div class="gird-item row_04 rowEnd">@itemParent.MenuOrder</div>
            </div>
            
            List<Menu> lstMenuChil = lstMenu.Where(d => d.ParentID == itemParent.MenuID).OrderBy(d => d.MenuOrder).ToList();
            foreach (Menu menuChil in lstMenuChil)
            {
                string spanceChil = "&nbsp;&nbsp;&nbsp;&nbsp;" + menuChil.MenuName;
                <div class="gird-row">
                    <div class="gird-item row_01">
                        <div class="checkbox" onclick="SetChecked($(this));" id="@menuChil.MenuID" >
                            @Html.Hidden("oder",menuChil.MenuID)                            
                        </div>
                    </div>
                    <div class="gird-item row_02"> @Html.Raw(spanceChil) + @menuChil.MenuName</div>
                    <div class="gird-item row_03">@menuChil.MenuUrl</div>
                    <div class="gird-item row_04 rowEnd">@menuChil.MenuOrder</div>
                </div>
            }
        
        }
     }

   
</div>


@section Toolbar {
<a class="btn_boder btn_new" onclick="openNew()">New</a>

<a class="btn_boder btn_edit" onclick="openEdit()" >Edit</a>
<a class="btn_boder btn_delete">Delete</a>

}


@section HeaderContent{
    <script type="text/javascript">
        
        function openNew() {
            window.location.assign("/menu/openEditMenu?id=0");
        }

        function openEdit() {
            var lstSelected = "";
            $("div.row_01 div.checked").each(function () {
                //$(this).attr('name');
                lstSelected = lstSelected + ";" + $(this).attr("id");
            });

            var lsCount = lstSelected.length;

            if (lsCount > 37) {
                cusAlert("Bạn chỉ cập nhật thông tin 1 nguoi...");
            }
            else if (lsCount <= 0) {
                cusAlert("Vui lòng chọn 1 người để cập nhật");
            }
            else {

                var _DisCode = lstSelected.split(";");
                itemcode = _DisCode[1];

                var dt = new Date();
                var href = "/menu/openEditMenu?id=" + itemcode + "&dt=" + dt.getTime();
                window.location.assign(href);
            }

        }

    </script>
}
